package com.paradogs.framework.core.annoations.request;

import com.paradogs.framework.core.msg.PRMsg;
import com.paradogs.framework.core.msg.route.MsgMapping;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: yumi
 * @date: 2023/8/25  17:28
 * @Description: TODO
 */
@Slf4j
public class PRMsgMappingHolder {

    private static Map<String, MsgMapping> mappingMap = new HashMap<>();

    public static MsgMapping put(String route, MsgMapping mapping) {
        return mappingMap.put(route, mapping);
    }

    /**
     * 获取映射
     * @param route
     * @return
     */
    public static MsgMapping getMsgMapping(String route) {
        return PRMsgMappingHolder.mappingMap.get(route);
    }

    /**
     * 获取路由映射的传参数据对象类型
     * @param route
     * @return
     */
    public static Class<?> getMsgMappingClass(String route) {
        MsgMapping msgMapping = PRMsgMappingHolder.getMsgMapping(route);
        if (msgMapping == null || msgMapping.getMsgClass() == null || msgMapping.getMsgClass().isAssignableFrom(void.class)) {
            return null;
        }
        return msgMapping.getMsgClass();
    }

    /**
     * 是否存在对应路由映射
     * @param route
     * @return
     */
    public static boolean containsRoute(String route) {
        return PRMsgMappingHolder.mappingMap.containsKey(route);
    }

}
